import os
import face_recognition
path=".\\testimge"
files=os.listdir(path)
testimge_names=[]
testimge_faces=[]
for file in files:
    filename=str(file)
    testimge_names.append(filename)
    image=face_recognition.load_image_file(path+'\\'+filename)
    encoding=face_recognition.face_encodings(image)[0]
    testimge_faces.append(encoding)
unknown_image=face_recognition.load_image_file("no1.jpg")
unknown_encoding=face_recognition.face_encodings(unknown_image)[0]
results=face_recognition.compare_faces(testimge_faces,unknown_encoding,tolerance=0.5)
print('人脸识别检测结果如下：')
for i in range(len(testimge_names)):
    print(testimge_names[i]+':',end=' ')
    if results[i]:
        print('检测到相同')
    else:
        print('不同')